package com.liu.concurrent.sync;

/**
 * 方法
 * synchronized 静态方法->类锁
 */
public class SyncTest3 implements Runnable {
	public void run() {
		syso();
		syso1();
	}

	public synchronized static void syso() {
		try {
			System.out.println(Thread.currentThread().getName() + "_Start");
			Thread.sleep(2000);
			System.out.println(Thread.currentThread().getName() + "_End");
			System.err.println("-----------------------------------------");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public static synchronized void syso1() {
		try {
			System.out.println(Thread.currentThread().getName() + "_Start");
			Thread.sleep(2000);
			System.out.println(Thread.currentThread().getName() + "_End");
			System.err.println("-----------------------------------------");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) throws InterruptedException {
		SyncTest3 syncTest1 = new SyncTest3();
		SyncTest3 syncTest2 = new SyncTest3();
		Thread thread1 = new Thread(syncTest1, "thread1");
		Thread thread2 = new Thread(syncTest2, "thread2");
		thread1.start();
		thread2.start();
	}
}